// This file is a part of ChaosDB.
// Copyright (C) 2012 ChaoJianPeng
// email:chaojianpeng@gmail.com
//
// ChaosDB is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// ChaosDB is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

/*
 * client_test.cpp
 *
 *  Created on: 2012-3-2
 *      Author: chao
 */

#include "db_client.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "time.h"

int main() {
	dbInit("tcp://127.0.0.1:5555");

	char* k = "11111";
	char* v = "sdbhyvgshadgf";
	char* k2 = "12333";
	char* v2 = "vhg12";
	char* k3 = "12334";
	char* v3 = "vhg33";
	char* k4 = "12335";
	char* v4 = "vhg44";
	char* k5 = "12336";
	char* v5 = "vhg55";
	char* k6 = "12339";
	char* v6 = "vheqweg55";

	char* i1 = "dfhusdfh";

	dbAdd(k, v, strlen(k), strlen(v) + 1);
	dbAdd(k2, v2, strlen(k2), strlen(v2) + 1);
	dbAdd(k3, v3, strlen(k3), strlen(v3) + 1);
	dbAdd(k4, v4, strlen(k4), strlen(v4) + 1);
	dbAdd(k5, v5, strlen(k5), strlen(v5) + 1);
	dbAdd(k6, v6, strlen(k6), strlen(v6) + 1);
	dbAddIndex(i1, k, strlen(i1), strlen(k));

	char* rv = (char*) dbGetByIndex(i1, strlen(i1));
	printf("接收key：k:%s\n", rv);

	dbDelIndex(i1, strlen(i1));
	dbReplace(k, v2, strlen(k), strlen(v2) + 1);

	rv = (char*) dbGet(k, strlen(k));
	printf("接收key：k:%s\n", rv);
	dbRemove(k, strlen(k));


	rv = (char*) dbGet(k2, strlen(k2));

}

